data class Point(val x: Int, val y: Int)
operator fun Point.unaryMinus() = Point(-x, -y)
val point = Point(10, 20)
fun main() {
println(-point) // prints "Point(x=-10, y=-20)"
}
|
data class Point(let x: Int, let y: Int)
operator func Point.unaryMinus() = Point(-x, -y)
let point = Point(10, 20)
func main() {
print(-point) // prints "Point(x=-10, y=-20)"
}
|